
<div id="templatemo_upcomming_event" class="container_wapper">
    <div class="container">
        <h1 align="center" style="font-family: calibri; margin-bottom: 20px;"> -------------------Deposit Saldo-------------------</h1>

        <table id="table-content">
            <form id="submitRequest" name="submitRequest" action="<?php echo site_url('transaksi/do_upload_smskit'); ?>" method="post" enctype="multipart/form-data">
                <tr>
                    <td align="right">Saldo Saat Ini</td>
                    <td>:</td>
                    <td>Rp. <?php echo number_format($saldo, 0, ',', '.'); ?>,-</td>
                </tr>
                <tr>
                    <td align="right">Pilih Bank Tujuan Transfer</td>
                    <td>:</td>
                    <td><input checked type="radio" class="pilihan_bank" name="pilihan_bank" value="bca">&nbsp;BCA : <b>0620-3683-42</b> (Akh Mirza Alief Syahrial)</td>
                </tr>
                <tr>
                    <td align="right">&nbsp;</td>
                    <td>&nbsp;</td>
                    <td><input type="radio" class="pilihan_bank" name="pilihan_bank" value="mandiri">&nbsp;Mandiri : <b>1410-0127-60559</b> (Akh Mirza Alief Syahrial)</td>
                </tr>
                <tr>
                    <td align="right">Masukkan Nominal Transfer</td>
                    <td>:</td>
                    <td><input id="nominal_transfer" type="text" name="nominal_transfer" onblur="sayit()"></td>
                </tr>
                <tr>
                    <td align="right">&nbsp;</td>
                    <td></td>
                    <td><div id="terbilang"></p></td>
                </tr>
            </form>
            <tr>
                <td></td>
                <td></td>
                <td><input type="button" id="bt_request" name="bt_request" class="button_blue" value="Kirim"></td>
            </tr>
        </table>
    </div>
</div>
<script>
    $(function() {
        $("#bt_request").click(function(event) {
            var v_nominal_transfer = parseFloat(document.getElementById('nominal_transfer').value);

            var radios = document.getElementsByName('pilihan_bank');
            
            var v_pilihan_bank = "";
            for (var i = 0, length = radios.length; i < length; i++) {
                if (radios[i].checked) {
                    // do whatever you want with the checked radio
                    v_pilihan_bank = radios[i].value;                    
                    break;
                }
            }            

            if (v_nominal_transfer < 10000 || !v_nominal_transfer) {
                show_alert("Nominal transfer minimal Rp. 10.000,- (Sepuluh Ribu Rupiah)");
            } else {
                show_dialog("Silahkan tunggu, request deposit anda sedang kami proses...");
                $.ajax({
                    url: '<?php echo base_url(); ?>index.php/transaksi/request_deposit',
                    type: "POST",
                    timeout: 30000,
                    data: {
                        nominal_transfer: v_nominal_transfer,
                        pilihan_bank: v_pilihan_bank,
                        '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
                    },
                    success: function(result)
                    {
                        var obres = $.parseJSON(result);
                        var err_code = obres.err_code;

                        if (err_code !== "00") {
                            hide_dialog(obres.msg);
                        }
                        else
                        {
                            hide_dialog(obres.msg);
                        }
                    },
                    error: function()
                    {
                        hide_dialog("Terdapat masalah dengan koneksi internet anda, silahkan coba kembali.");
                    }
                });
            }
        });
    });


    function sayit() {
        s = document.getElementById('nominal_transfer').value;
        if (s !== "") {
            var thousand = Array("", "Ribu", "Juta", "Milyar", "Trilyun");
            s = Math.round(s * Math.pow(10, 2)) / Math.pow(10, 2);
            s = String(s);
            s = s.split(".");
            var word = s[0];
            var cent = s[1] ? s[1] : "0";
            if (cent.length < 2)
                cent += "0";

            var subword = "";
            i = 0;
            while (word.length > 3) {
                subdigit = threedigit(word.substr(word.length - 3, 3));
                subword = subdigit + (subdigit != "" ? " " + thousand[i] + " " : "") + subword;
                word = word.substring(0, word.length - 3);
                i++;
            }
            subword = threedigit(word) + " " + thousand[i] + " " + subword;
            subword = subword.replace(/^ +$/gi, "");

            word = (subword == "" ? "NOL" : subword.toUpperCase()) + " RUPIAH";
            subword = threedigit(cent);
            cent = (subword == "" ? "" : " ") + subword.toUpperCase() + (subword == "" ? "" : " SEN");

            $("#terbilang").html(word + cent);
        } else {
            $("#terbilang").html("");
        }
    }

    var thoudelim = ".";
    var decdelim = ",";
    var curr = "Rp ";
    var d = document;

    // format(1000000.5,3) : 1.000.000,500
    // format(1000000.55555,3) : 1.000.000,556

    function format(s, r) {
        s = Math.round(s * Math.pow(10, r)) / Math.pow(10, r);
        s = String(s);
        s = s.split(".");
        var l = s[0].length;
        var t = "";
        var c = 0;
        while (l > 0) {
            t = s[0][l - 1] + (c % 3 == 0 && c != 0 ? thoudelim : "") + t;
            l--;
            c++;
        }
        s[1] = s[1] == undefined ? "0" : s[1];
        for (i = s[1].length; i < r; i++) {
            s[1] += "0";
        }
        return curr + t + decdelim + s[1];
    }

    function threedigit(word) {
        eja = Array("Nol", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan");
        while (word.length < 3)
            word = "0" + word;
        word = word.split("");
        a = word[0];
        b = word[1];
        c = word[2];
        word = "";
        word += (a != "0" ? (a != "1" ? eja[parseInt(a)] : "Se") : "") + (a != "0" ? (a != "1" ? " Ratus" : "ratus") : "");
        word += " " + (b != "0" ? (b != "1" ? eja[parseInt(b)] : "Se") : "") + (b != "0" ? (b != "1" ? " Puluh" : "puluh") : "");
        word += " " + (c != "0" ? eja[parseInt(c)] : "");
        word = word.replace(/Sepuluh ([^ ]+)/gi, "$1 Belas");
        word = word.replace(/Satu Belas/gi, "Sebelas");
        word = word.replace(/^[ ]+$/gi, "");

        return word;
    }

</script>
</body>
</html>